#define DEBUG
#include <cstdio>
#include <cmath>
#define MAXN 100000

using namespace std;

void correct(int *s, int n, int a, int b) {
  static int temp[MAXN+1];
  temp[0]=0;
  for (int i=n+1; i>0; i--) {
    if (s[i]==b) {
      temp[++temp[0]] = i;
    }
    if (s[i]==a) {
      if (temp[0]) {
	s[i]+=4;
	s[temp[temp[0]]]-=4;
	temp[0]--;
      }
    }
  }
}

int main() {
#ifdef DEBUG
  freopen("2.in", "r", stdin);
  freopen("2.out", "w", stdout);
#endif

  int t;
  scanf("%d", &t);
  for (int ti=1; ti<=t; ti++) {
    static int a[MAXN+1], b[MAXN+1], s[MAXN+2];
    int n, ans=0;
    scanf("%d", &n);
    for (int i=1; i<=n; i++) {
      scanf("%d", a+i);
    }
    for (int i=1; i<=n; i++) {
      scanf("%d", b+i);
      s[i] = (b[i]+4-a[i])%4-(b[i-1]+4-a[i-1])%4;
    }
    s[n+1]=-((b[n]+4-a[n])%4);
    correct(s, n, -3, 3);
    correct(s, n, -3, 2);
    correct(s, n, -2, 3);
    for (int i=1; i<=n; i++) {
      if (s[i]>0) {
	ans += s[i];
      }
    }
    printf("%d\n", ans);
  }

  fclose(stdin);
  fclose(stdout);
  return 0;
}
